package com.sychip.fhc.app.data.source.dao


import androidx.room.Dao
import androidx.room.Query
import androidx.room.Upsert
import com.sychip.fhc.app.data.source.entity.WsnTestRecordEntity
import kotlinx.coroutines.flow.Flow

const val TBL_WsnTestRecord = "wsnTestRecord"
@Dao
interface WsnTestRecordDao {
/**
 * Observes list of tasks.
 *
 * @return all tasks.
 */
@Query("SELECT * FROM $TBL_WsnTestRecord WHERE usbId = :usbId")
fun observeAll(usbId: String): Flow<List<WsnTestRecordEntity>>



/**
 * Select all tasks from the tasks table.
 *
 * @return all tasks.
 */
@Query("SELECT * FROM $TBL_WsnTestRecord WHERE usbId = :usbId")
suspend fun getAll(usbId: String): List<WsnTestRecordEntity>

@Query("SELECT * FROM $TBL_WsnTestRecord WHERE fromTime = :fromTime")
suspend fun getByFromTime(fromTime: Long): WsnTestRecordEntity


    /**
 * Insert or update a bleDevice in the database. If a bleDevice already exists, replace it.
 *
 * @param bleDevice the bleDevice to be inserted or updated.
 */
@Upsert
suspend fun upsert(bleDevice: WsnTestRecordEntity)


/**
 * Delete a bleDevice by id.
 *
 * @return the number of tasks deleted. This should always be 1.
 */
@Query("DELETE FROM $TBL_WsnTestRecord WHERE fromTime = :fromTime")
suspend fun deleteByFromTime(fromTime: Long): Int

/**
 * Delete all tasks.
 */
@Query("DELETE FROM $TBL_WsnTestRecord WHERE usbId = :usbId")
suspend fun deleteAll(usbId: String): Int

}
